﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
* 项目名称 ：APP.Trading.Service
* 项目描述 ：
* 类 名 称 ：WithdrawService
* 类 描 述 ：
* 所在的域 ：DESKTOP-07DQ4D0
* 命名空间 ：APP.Trading.Service
* 机器名称 ：DESKTOP-07DQ4D0 
* CLR 版本 ：4.0.30319.42000
* 作    者 ：Me.笨先生 (66623978)
* 创建时间 ：2018/2/14 16:38:26
* 更新时间 ：2018/2/14 16:38:26
* 版 本 号 ：v1.0.0.0
*******************************************************************
* Copyright @ admin 2018. All rights reserved.
*******************************************************************
//----------------------------------------------------------------*/
#endregion

using APP.Trading.Entity;
using APP.Account.Entity;

using APP.CommonLib.Cache;
using APP.CommonLib.Utils;
using APP.CommonLib.Config;
using APP.CommonLib.XService;

using APP.Repository;
using APP.Repository.SqlServer;

namespace APP.Trading.Service
{
    /// <inheritdoc />
    /// <summary>
    /// 提现
    /// </summary>
    public class WithdrawService : IServiceHandler
    {
        private static readonly MsSqlContext BasicContext = new MsSqlContext(ConfigManager.GetWebConn("basic"));
        private static readonly MsSqlContext TradeContext = new MsSqlContext(ConfigManager.GetWebConn("trading"));
        public ServiceResult Invoke(ServiceRequest req)
        {
            var param = JsonHelper.JsonDeserialize<WithdrawParameter>(req.data);
            if (param.MemberId < 1)
            {
                return ServiceResult.Exception(ServiceResultStatus.InvalidToken, "登录失效,请重新登录");
            }
            if (param.Amount < 10)
            {
                return ServiceResult.Exception(ServiceResultStatus.Tip, "提现最低10元起");
            }

            var mid = param.MemberId;
            var member = BasicContext.Query<MemberEntity>().Where(t => t.IsDelete == 0 && t.Id == mid).FirstOrDefault();
            if (member == null || member.BankCardAuthen == 0 || member.RealNameAuthen == 0)
            {
                return ServiceResult.Exception(ServiceResultStatus.Tip, "未完成实名认证");
            }
            if (member.BankCardAuthen == 2)
            {
                return ServiceResult.Exception(ServiceResultStatus.Tip, "银行卡正在审核中");
            }

            var rdsWithdrawCache = CacheManager.GetRedisCache(RedisKeyNameSpace.MemberWithdrawNameSapce, mid.ToString());
            if (!string.IsNullOrEmpty(rdsWithdrawCache))
            {
                return ServiceResult.Exception(ServiceResultStatus.Tip, "操作过于频繁");
            }

            TradeContext.Query<MemberAccountEntity>().Where(t => t.MemberId == mid && t.IsDelete == 0).FirstOrDefault();
            bool needSetTradingPwd = false;
            int errorCount;

            if (needSetTradingPwd)
            {

            }

            long orderId = 0;

            var parameters = new DbParam();
            return ServiceResult.Exception(ServiceResultStatus.Tip, "提现失败");
        }
    }
}